package com.yuyou.fn.educational.service.impl;

import com.github.wens.mybatisplus.examples.Example;
import com.yuyou.fn.common.util.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.yuyou.fn.educational.mapper.BaseSubjectMapper;
import com.yuyou.fn.educational.entity.BaseSubject;
import com.yuyou.fn.educational.service.IBaseSubjectService;
import com.github.wens.framework.service.impl.SuperServiceImpl;

import java.util.List;

/**
 *
 * BaseSubject 表数据服务层接口实现类
 *
 */
@Service
public class BaseSubjectServiceImpl extends SuperServiceImpl<BaseSubjectMapper, BaseSubject,Long> implements IBaseSubjectService {

    @Cacheable("CacheOfSubjectList")
    @Override
    public List<BaseSubject> findAllFromCache() {
        Example<BaseSubject> example = BaseSubject.createExample();
        return findListByExample(example);
    }

    @Override
    public List<String> findSubjectNameByIds(List<Long> subjectIds) {
        Example<BaseSubject> example = BaseSubject.createExample();
        example.selectProperties("subjectName");
        example.createCriteria().andIn("subjectId",subjectIds );
        return BeanUtils.toList(findListByExample(example),"subjectName");
    }

    @Override
    public String findGradNameById(Long subjectId) {

        Example<BaseSubject> example = BaseSubject.createExample();
        example.selectProperties("subjectName");
        example.createCriteria().andEqualTo("subjectId",subjectId);
        BaseSubject baseSubject = findOneByExample(example);

        return baseSubject == null ? StringUtils.EMPTY : baseSubject.getSubjectName() ;
    }

    @Override
    public BaseSubject findSubjectBySubjectName(String subjectName) {
        Example<BaseSubject> example = BaseSubject.createExample();
        example.createCriteria().andEqualTo("subjectName",subjectName);
        return findOneByExample(example);
    }
}